import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
} from "typeorm";
import { ApiProperty } from "@nestjs/swagger"; // 引入 Swagger 注解

@Entity("sys_user",{database:'daijia_system'}) // 指定表名
export class SysUser {
  @ApiProperty({ description: "主键id", example: 1 })
  @PrimaryGeneratedColumn({ type: "bigint", comment: "主键id"})
  id: number;

  @ApiProperty({ description: "用户名", example: "admin", maxLength: 20 })
  @Column({ length: 20, nullable: false, default: "", comment: "用户名" })
  @Index({ unique: true }) // 设置唯一索引
  username: string;

  @ApiProperty({ description: "密码", example: "password123", maxLength: 32 })
  @Column({ length: 32, nullable: false, default: "", comment: "密码" })
  password: string;

  @ApiProperty({ description: "姓名", example: "张三", maxLength: 50, required: false })
  @Column({ length: 50, nullable: true, comment: "姓名" })
  name: string;

  @ApiProperty({ description: "手机号", example: "12345678901", maxLength: 11, required: false })
  @Column({ length: 11, nullable: true, comment: "手机号" })
  phone: string;

  @ApiProperty({ description: "头像地址", example: "http://example.com/avatar.jpg", maxLength: 200, required: false })
  @Column({ length: 200, nullable: true, comment: "头像地址" })
  headUrl: string;

  @ApiProperty({ description: "部门id", example: 101, required: false })
  @Column({ type: "bigint", nullable: true, comment: "部门id" })
  deptId: number;

  @ApiProperty({ description: "岗位id", example: 201, required: false })
  @Column({ type: "bigint", nullable: true, comment: "岗位id" })
  postId: number;

  @ApiProperty({ description: "描述", example: "这是一个用户描述", maxLength: 255, required: false })
  @Column({ length: 255, nullable: true, comment: "描述" })
  description: string;

  @ApiProperty({ description: "状态：1-启用，0-禁用", example: 1, enum: [0, 1], required: false })
  @Column({
    type: "tinyint",
    nullable: true,
    comment: "状态：1-启用，0-禁用",
  })
  status: number;

  @ApiProperty({ description: "创建时间", example: "2023-01-01T00:00:00Z", readOnly: true })
  @CreateDateColumn({
    type: "timestamp",
    comment: "创建时间",
  })
  createTime: Date;

  @ApiProperty({ description: "更新时间", example: "2023-01-01T00:00:00Z", readOnly: true })
  @UpdateDateColumn({
    type: "timestamp",
    comment: "更新时间",
  })
  updateTime: Date;

  @ApiProperty({ description: "逻辑删除标识：0-未删除，1-已删除", example: 0, enum: [0, 1] })
  @Column({
    type: "tinyint",
    nullable: false,
    default: 0,
    comment: "逻辑删除标识：0-未删除，1-已删除",
  })
  isDeleted: number;
}